package com.ruoyi.html.handle.service.impl;

import com.ruoyi.game.api.domin.GameItem;
import com.ruoyi.html.handle.annotation.SelectType;
import com.ruoyi.html.handle.service.ISelectHandleService;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Option解析
 *
 * @author : 小胖
 * @version : 1.0
 * @date : 2022/05/08  16:31
 **/
@Service
@SelectType("option")
public class OptionHandleServiceImpl implements ISelectHandleService
{
    /**
     * 下拉框处理
     *
     * @param html html
     * @return 游戏物品
     */
    @Override
    public List<GameItem> selectHandle(String html)
    {
        return Jsoup.parse(html).getElementsByTag("option")
                .stream()
                .map(element ->
                {
                    GameItem gameItem = new GameItem();
                    gameItem.setItemId(element.attr("value"));
                    gameItem.setItemName(element.text());
                    return gameItem;
                }).collect(Collectors.toList());
    }
}
